home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_qt.idb / usr / freeware / include / Qt / qintcache.h.z / qintcache.h
Encoding:
C/C++ Source or Header  |  1998-10-28  |  7.8 KB  |  184 lines

  1. /****************************************************************************
  2. ** $Id: qintcache.h,v 2.4 1998/07/03 00:09:46 hanord Exp $
  3. **
  4. ** Definition of QIntCache template/macro class
  5. **
  6. ** Created : 950209
  7. **
  8. ** Copyright (C) 1992-1998 Troll Tech AS.  All rights reserved.
  9. **
  10. ** This file is part of Qt Free Edition, version 1.40.
  11. **
  12. ** See the file LICENSE included in the distribution for the usage
  13. ** and distribution terms, or http://www.troll.no/free-license.html.
  14. **
  15. ** IMPORTANT NOTE: You may NOT copy this file or any part of it into
  16. ** your own programs or libraries.
  17. **
  18. ** Please see http://www.troll.no/pricing.html for information about 
  19. ** Qt Professional Edition, which is this same library but with a
  20. ** license which allows creation of commercial/proprietary software.
  21. **
  22. *****************************************************************************/
  23.  
  24. #ifndef QINTCACHE_H
  25. #define QINTCACHE_H
  26.  
  27. #ifndef QT_H
  28. #include "qgcache.h"
  29. #endif // QT_H
  30.  
  31.  
  32. #if defined(USE_MACROCLASS)
  33.  
  34. #include "qgeneric.h"
  35.  
  36. #if !defined(name2)
  37. #define name2(a,b)    name2_xx(a,b)
  38. #define name2_xx(a,b) a##b
  39. #endif
  40.  
  41. #if defined(DEFAULT_MACROCLASS)
  42. #define QIntCachedeclare QIntCacheMdeclare
  43. #define QIntCache QIntCacheM
  44. #endif
  45. #define QIntCacheM(type) name2(QIntCacheM_,type)
  46.  
  47. #define QIntCacheMdeclare(type)                              \
  48. class QIntCacheM(type) : public QGCache                          \
  49. {                                          \
  50. public:                                          \
  51.     QIntCacheM(type)( const QIntCacheM(type) &c ) : QGCache(c) {}          \
  52.     QIntCacheM(type)( int maxCost=100, int size=17 )                  \
  53.     : QGCache( maxCost, size, FALSE, FALSE, TRUE ) {}              \
  54.    ~QIntCacheM(type)()              { clear(); }                  \
  55.     QIntCacheM(type) &operator=( const QIntCacheM(type) &c )              \
  56.             { return (QIntCacheM(type)&)QGCache::operator=(c); }  \
  57.     int      maxCost()   const          { return QGCache::maxCost(); }          \
  58.     int      totalCost() const          { return QGCache::totalCost(); }          \
  59.     void  setMaxCost( int m )          { QGCache::setMaxCost(m); }          \
  60.     uint  count()     const          { return QGCache::count(); }          \
  61.     uint  size()      const          { return QGCache::size(); }          \
  62.     bool  isEmpty()   const          { return QGCache::count() == 0; }          \
  63.     bool  insert( long k, const type *d, int c=1, int p=0 )              \
  64.             { return QGCache::insert((const char*)k,(GCI)d,c,p); }\
  65.     bool  remove( long k )   { return QGCache::remove((const char *)k); }     \
  66.     type *take( long k )     { return (type *)QGCache::take((const char *)k);}\
  67.     void  clear()              { QGCache::clear(); }              \
  68.     type *find( long k, bool ref=TRUE ) const                      \
  69.             { return (type *)QGCache::find( (const char *)k,ref);}\
  70.     type *operator[]( long k ) const                          \
  71.             { return (type *)QGCache::find( (const char *)k); }   \
  72.     void  statistics() const          { QGCache::statistics(); }          \
  73. private:                                      \
  74.     void  deleteItem( GCI d )          { if ( del_item ) delete (type *)d; }   \
  75. }
  76.  
  77. #if defined(DEFAULT_MACROCLASS)
  78. #define QIntCacheIteratordeclare QIntCacheIteratorMdeclare
  79. #define QIntCacheIterator QIntCacheIteratorM
  80. #endif
  81. #define QIntCacheIteratorM(type) name2(QIntCacheIteratorM_,type)
  82.  
  83. #define QIntCacheIteratorMdeclare(type)                          \
  84. class QIntCacheIteratorM(type) : public QGCacheIterator                  \
  85. {                                          \
  86. public:                                          \
  87.     QIntCacheIteratorM(type)( const QIntCacheM(type) &c )              \
  88.                   : QGCacheIterator( (QGCache &)c ) {}          \
  89.     QIntCacheIteratorM(type)( const QIntCacheIteratorM(type) &ci )          \
  90.                   : QGCacheIterator( (QGCacheIterator &)ci ) {}   \
  91.     QIntCacheIteratorM(type) &operator=( const QIntCacheIteratorM(type)&ci )  \
  92.     { return (QIntCacheIteratorM(type)&)QGCacheIterator::operator=(ci); } \
  93.     uint  count()   const    { return QGCacheIterator::count(); }          \
  94.     bool  isEmpty() const    { return QGCacheIterator::count() == 0; }          \
  95.     bool  atFirst() const    { return QGCacheIterator::atFirst(); }          \
  96.     bool  atLast()  const    { return QGCacheIterator::atLast(); }          \
  97.     type *toFirst()         { return (type *)QGCacheIterator::toFirst(); }   \
  98.     type *toLast()         { return (type *)QGCacheIterator::toLast(); }    \
  99.     operator type *() const  { return (type *)QGCacheIterator::get(); }          \
  100.     type *current()   const  { return (type *)QGCacheIterator::get(); }          \
  101.     const char *currentKey() const                          \
  102.                  { return QGCacheIterator::getKey();}          \
  103.     type *operator()()         { return (type *)QGCacheIterator::operator()();} \
  104.     type *operator++()         { return (type *)QGCacheIterator::operator++();} \
  105.     type *operator+=(uint j) { return (type *)QGCacheIterator::operator+=(j);}\
  106.     type *operator--()         { return (type *)QGCacheIterator::operator--();} \
  107.     type *operator-=(uint j) { return (type *)QGCacheIterator::operator-=(j);}\
  108. }
  109.  
  110. #endif // USE_MACROCLASS
  111.  
  112.  
  113. #if defined(USE_TEMPLATECLASS)
  114.  
  115. #if defined(DEFAULT_TEMPLATECLASS)
  116. #undef    QIntCache
  117. #define QIntCache QIntCacheT
  118. #endif
  119.  
  120. template<class type> class QIntCacheT : public QGCache
  121. {
  122. public:
  123.     QIntCacheT( const QIntCacheT<type> &c ) : QGCache(c) {}
  124.     QIntCacheT( int maxCost=100, int size=17 )
  125.     : QGCache( maxCost, size, FALSE, FALSE, TRUE ) {}
  126.    ~QIntCacheT()         { clear(); }
  127.     QIntCacheT<type> &operator=( const QIntCacheT<type> &c )
  128.             { return (QIntCacheT<type>&)QGCache::operator=(c); }
  129.     int      maxCost()   const  { return QGCache::maxCost(); }
  130.     int      totalCost() const  { return QGCache::totalCost(); }
  131.     void  setMaxCost( int m) { QGCache::setMaxCost(m); }
  132.     uint  count()     const  { return QGCache::count(); }
  133.     uint  size()      const  { return QGCache::size(); }
  134.     bool  isEmpty()   const  { return QGCache::count() == 0; }
  135.     bool  insert( long k, const type *d, long c=1, int p=0 )
  136.             { return QGCache::insert((const char*)k,(GCI)d,c,p); }
  137.     bool  remove( long k )   { return QGCache::remove((const char *)k); }
  138.     type *take( long k )     { return (type *)QGCache::take((const char *)k);}
  139.     void  clear()              { QGCache::clear(); }
  140.     type *find( long k, bool ref=TRUE ) const
  141.             { return (type *)QGCache::find( (const char *)k,ref);}
  142.     type *operator[]( long k ) const
  143.             { return (type *)QGCache::find( (const char *)k); }
  144.     void  statistics() const { QGCache::statistics(); }
  145. private:
  146.     void  deleteItem( GCI d ){ if ( del_item ) delete (type *)d; }
  147. };
  148.  
  149.  
  150. #if defined(DEFAULT_TEMPLATECLASS)
  151. #undef    QIntCacheIterator
  152. #define QIntCacheIterator QIntCacheIteratorT
  153. #endif
  154.  
  155. template<class type> class QIntCacheIteratorT : public QGCacheIterator
  156. {
  157. public:
  158.     QIntCacheIteratorT( const QIntCacheT<type> &c )
  159.     : QGCacheIterator( (QGCache &)c ) {}
  160.     QIntCacheIteratorT( const QIntCacheIteratorT<type> &ci )
  161.                   : QGCacheIterator((QGCacheIterator &)ci) {}
  162.     QIntCacheIteratorT<type> &operator=( const QIntCacheIteratorT<type>&ci )
  163.     { return ( QIntCacheIteratorT<type>&)QGCacheIterator::operator=( ci );}
  164.     uint  count()   const     { return QGCacheIterator::count(); }
  165.     bool  isEmpty() const     { return QGCacheIterator::count() == 0; }
  166.     bool  atFirst() const     { return QGCacheIterator::atFirst(); }
  167.     bool  atLast()  const     { return QGCacheIterator::atLast(); }
  168.     type *toFirst()          { return (type *)QGCacheIterator::toFirst(); }
  169.     type *toLast()          { return (type *)QGCacheIterator::toLast(); }
  170.     operator type *()  const  { return (type *)QGCacheIterator::get(); }
  171.     type *current()    const  { return (type *)QGCacheIterator::get(); }
  172.     long  currentKey() const  { return (long)QGCacheIterator::getKey();}
  173.     type *operator()()          { return (type *)QGCacheIterator::operator()();}
  174.     type *operator++()          { return (type *)QGCacheIterator::operator++(); }
  175.     type *operator+=(uint j)  { return (type *)QGCacheIterator::operator+=(j);}
  176.     type *operator--()          { return (type *)QGCacheIterator::operator--(); }
  177.     type *operator-=(uint j)  { return (type *)QGCacheIterator::operator-=(j);}
  178. };
  179.  
  180. #endif // USE_TEMPLATECLASS
  181.  
  182.  
  183. #endif // QINTCACHE_H
  184.